<?php

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';
ini_set('memory_limit', '512M');

use Biz\model\brand\Content;
use Doraemon\pockets\config\IniConfig;
use Doraemon\tools\Presto\PrestoClientV2;
use Medoo\Medoo;

echo(ini_get('memory_limit')), PHP_EOL;
$brand_id = $argv[1] ?? 0;
if (!$brand_id) {
    echo 'brand id is empty';
    die;
}

$result = Content::select([
    'obj_id' => Medoo::raw('DISTINCT(obj_id)'),
], ['brand_id' => $brand_id, 'claim_content_status' => [Content::CLAIM_CONTENT_DONE, Content::CLAIM_CONTENT_MATCH]]);
$result = array_column($result, 'obj_id');

$config = IniConfig::getConfigSelect('presto', 'brand');
$presto = new PrestoClientV2("{$config['host']}:{$config['port']}/{$config['path']}", "hive", $config["username"], $config["password"]);
$objIds = [];
$page = 1;
$pageSize = 500;
$delObjIds = [];
do {
    var_dump($page);
    $offset = ($page - 1) * $pageSize;
    $objIds = array_slice($result, $offset, $pageSize);
    $ids = implode("','", $objIds);
    $sql = "select id,status from oss.dwd.hhz_photos  where id in ('" . $ids . "') and status=9";
    $presto->Query($sql);
    $presto->WaitQueryExec();
    $list = $presto->GetData();
    foreach ($list as $row) {
        $objId = $row[0];
        $status = $row[1];
        $delObjIds[] = $objId;
        var_dump($delObjIds);
        //Content::update(['claim_content_status' => 0], ['obj_id' => $objId]); 修复状态为初始化状态
    }
    $page++;
} while ($objIds);
$delObjIds = array_unique(array_filter($delObjIds));
var_dump('brand_id:' . $brand_id . '发现' . count($delObjIds) . '个已删除的note');
$delids = implode("','", $delObjIds);
$sql = "select * from brand_content  where id in ('" . $delids . "')";
var_dump($sql);
die;





